#include "setpawidget.h"
#include "ui_setpawidget.h"

SetPaWidget::SetPaWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SetPaWidget)
{
    ui->setupUi(this);
    initUI();

    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(slt_button()));
}

SetPaWidget::~SetPaWidget()
{
    delete ui;
}

void SetPaWidget::initUI()
{
    ui->lineEdit->setText(Parameters::cmsaddr.mid(3));
    ui->lineEdit_2->setText(Parameters::phone.mid(3));
    ui->spinBox->setValue(Parameters::interval_time);
    ui->spinBox_2->setValue(Parameters::interval);
    ui->spinBox_3->setValue(Parameters::TestDuration);
    ui->spinBox_4->setValue(Parameters::boundaryValue);
    ui->spinBox_5->setValue(Parameters::spaceTime);
}

void SetPaWidget::slt_button()
{

    if (help()) {
        QMessageBox::information(this,
                                 trUtf8("ERROR"),trUtf8("内容填写错误！"));
        return;
    }
    Parameters::cmsaddr = QString("+86") + ui->lineEdit->text().trimmed();
    Parameters::phone = QString("+86") + ui->lineEdit_2->text().trimmed();
    Parameters::interval_time = ui->spinBox->value();
    Parameters::interval = ui->spinBox_2->value();
    Parameters::TestDuration = ui->spinBox_3->value();
    Parameters::boundaryValue = ui->spinBox_4->value();
    Parameters::spaceTime = ui->spinBox_5->value();
}

bool SetPaWidget::help()
{
    return ui->lineEdit->text().isEmpty()
            | ui->lineEdit_2->text().isEmpty()
            | (ui->spinBox->value() < 0)
            | (ui->spinBox_2->value() < 0)
            | (ui->spinBox_3->value() < 0)
            | (ui->spinBox_4->value() < 0)
            | (ui->spinBox_5->value() < 0);
}

